<?php

/***  DOCUMENTATION LAYER

Ceo Sample Unit Test

Last Update: Aug 2007
  
DESCRIPTION
  this file provides a template for other simple unit tests.
  
NOTES
  $test_root dynamically sets root in order to keep tests working after
  they are moved to the __REPOSITORY directory
    
______________________________________________________________________________*/

$_tx0 = microtime();
$test_root = ( strpos(dirname(__FILE__), 'repository') === false ) ? '' : '../';


// Test Name
$test_name = 'sample test';

// Include Files
require_once($test_root . '../php_ceo/ext/input/form.class.php');

// Configure Test
$debug = 1;


// Test Procedure
	// build form
	$TestForm = new CeoForm($debug);
	$TestForm->add_element($name='password', $type='input_password',$label='password', $is_required=1);
	
	// debug
	if ( !empty($_POST) ) $TestForm->print_d('POST: ' . print_r($_POST,1), 'green');
	
	// field validity test
	if ( $TestForm->EL['password']->is_submitted && $TestForm->EL['email_input']->is_valid )
	{
		$TestForm->print_d('password input is valid', 'green');
	}
	elseif ( $TestForm->EL['password']->is_submitted )
	{
		$TestForm->print_d('password input is not valid', 'red');
	}
	
	// get form status
	if ( !$TestForm->is_submitted() ) $TestForm->print_d("<h3>form not submitted</h3>", '#ccc');
	elseif ( $TestForm->is_valid() ) $TestForm->print_d("<h3>form is valid</h3>", 'lime');
	else $TestForm->print_d("<h3>form is not valid</h3>", 'magenta');
	
	// print form
	$_HTML['submit_bx'] = $TestForm->add_button($type='submit', $label='submit it!');
	$_HTML['password'] = $TestForm->EL['password']->print_block();
	
	$_HTML['form'] = <<<HTML
<div class="form">
<form name="test" method="post" action="{$_SERVER['PHP_SELF']}">
{$_HTML['password']}
{$_HTML['submit_bx']}
</form>
</div>
HTML;

	echo $_HTML['form'];

	
	// debug
	$TestForm->EL['email_input']->random_var = 'this should be present in element object and form object';
	$TestForm->print_d("<br /><br />let's dump some objects");
	$TestForm->EL['email_input']->dump();
	$TestForm->dump();


// Footer
$_txn = microtime();
$stx = number_format(((substr($_txn,0,9)) + (substr($_txn,-10)) - (substr($_tx0,0,9)) - (substr($_tx0,-10))),4); 
echo "<h6>test '$test_name' complete in $stx s</h6>";
?>
